// pages/helpCarryer/helpCarryer.js
import  logFunction  from "../../utils/Log";
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
let sql = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  
  onSubmit() {
    // if (!getApp().globalData.userInfo) {
    //   console.log(logFunction);
      logFunction.logFunction.getUserProfile(this);
    // }
    // else{
      if (getApp().globalData.judgeUser) {
    sql.collection("orders").add({
      data: {
        pakingLocation: this.__data__.pakingLocation,
        getLocation: this.__data__.getLocation,
        time: this.__data__.time,
        thing: this.__data__.thing,
        priNum: this.__data__.priNum,
        ps: this.__data__.ps,
        type: "校园帮带",
        checked: this.__data__.checked,
        // userInfo.avatarUrl
        avatarUrl: getApp().globalData.userInfo.avatarUrl,
        nickName: getApp().globalData.userInfo.nickName,

      },
      success: (result) => {
        console.log(result);
        console.log("执行");
        Toast('SUCCESS!');
        
        console.log("执行2");
        setTimeout(() => {
          wx.navigateBack();
          
        }, 1000);
        console.log("执行3");
      },
      fail: (res) => {},
      complete: (res) => {
        
      }
    })
    }
    
  },

  selectLocation() {
    wx.navigateTo({
      url: '../addAddress/addAddress?data=pakingLocation',
    })
  },
  selectLocation2() {
    wx.navigateTo({
      url: '../addAddress/addAddress?data=getLocation',
    })
  },
  pakingLocationFun(e) {
    console.log(e.detail);
    this.setData({
      pakingLocation: e.detail,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let currentTime = this.getCurrentTime();
    this.setData({
      time: currentTime,
    })
  },
  getCurrentTime() {
    var month=new Date();
    console.log(month.getHours()+":"+month.getMinutes());
    let currentTime = month.getHours()+":"+month.getMinutes();
    this.setData({
      currentTime,
    })
    return currentTime;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    console.log(this.__data__.pri);
    var month=new Date();
    console.log(month.getHours()+":"+month.getMinutes());
    let nowTime = month.getHours()+":"+month.getMinutes();
    this.setData({
      time: nowTime
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})